package com.wdd.web.defaultt.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wdd.web.defaultt.dao.UserDao;
import com.wdd.web.defaultt.entity.User;
import com.wdd.web.defaultt.entity.UserEntity;
import com.wdd.web.defaultt.mapper.UserMapper;
import com.wdd.web.defaultt.service.UserService;

/**
 * @author wdd_think
 *	JdbcTemplate整合 springboot Jpa
 */
@RestController
public class UserController {
	//JdbcTemplate
	@Autowired
	private UserService userservice;//jdbc数据连接
	//springJpa
	@Autowired
	private UserDao userDao;//jpa数据连接
	@Autowired
	private UserMapper userMapper;//mybatyis 注解
	
	//http://localhost:8080/user?id=11&name=wqe&pwd=wer
	@GetMapping("/user")
    public String user(String id,String name,String pwd) {
		userservice.createUser(id, name, pwd);
        return "index";
    }
	@GetMapping("/getUser")
    public User getUser(Integer id) {
		User user = userDao.getOne(id);
		return user;
    }
	@GetMapping("/getUserList")
    public List<User> getUser() {
		List<User> list = userDao.findAll();
		return list;
    }
    @RequestMapping("/getOne2")
    public UserEntity getUser2(Long id) {
    	UserEntity user=userMapper.getOne(id);
        return user;
    }
    @RequestMapping("/jpaCreateUser")
    public String createUser(){
    	User user = new User();
    	user.setId(23);
    	user.setName("name23");
    	user.setPwd("pwd23");
    	userDao.save(user);
    	return "success";
    }
}
